﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectWebNhac.BUS;
using ProjectWebNhac.DTO;

namespace ProjectWebNhac.GUI.User
{
    public partial class UploadNhac : System.Web.UI.Page
    {
        BaiHatBus baihatBus = new BaiHatBus();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadTheLoai();
            }
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (Session["ThanhVien"]!=null)
            {
                NguoiDungDTO objUser = (NguoiDungDTO)Session["ThanhVien"];
                BaiHatDTO objBh = new BaiHatDTO();
                objBh.TenBaiHat = txtTenBH.Text;
                objBh.TenCaSi = txtCaSi.Text;
                objBh.TaiKhoan = objUser.TaiKhoan;
                objBh.MaTheLoai = Convert.ToInt16(drpTheLoai.SelectedValue);
                objBh.Lyrics = "";
                objBh.TrangThai = 0;
                objBh.LinkBaiHat = flUpNhac.FileName;
                if (flUpNhac.FileName.Length>0)
                {

                    if (baihatBus.ThemBaiHat(objBh))
                    {
                        try
                        {
                            Response.Redirect("BaiHat.aspx");
                            objBh.LinkBaiHat = flUpNhac.FileName;
                            flUpNhac.SaveAs(Server.MapPath("~/Nhac/" + objBh.LinkBaiHat));
                        }
                        catch (System.Exception ex)
                        {

                        }
                    }
                }
            }
        }
        private void LoadTheLoai()
        {
            TheLoaiBus theloaiBus = new TheLoaiBus();
            drpTheLoai.DataSource = theloaiBus.LayTheLoaiNhac();
            drpTheLoai.DataTextField = "TenTheLoai";
            drpTheLoai.DataValueField = "MaTheLoai";
            drpTheLoai.DataBind();
        }
    }
}